package leetcode.editor.week.week303;

public class Solution6125 {
    public static void main(String[] args) {
        new Solution6125().equalPairs(new int[][]{{3, 1, 2, 2}, {2, 4, 2, 2}, {2, 4, 2, 2}});
    }

    public int equalPairs(int[][] grid) {
        int m = grid.length;
        int res = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[0][j] == grid[i][0]) {
                    int k = i, t = j, count = 1;
                    boolean flag = true;
                    while (count < m) {
                        if (grid[k][count] != grid[count][j]) {
                            flag = false;
                            break;
                        }
                        count++;
                    }

                    if (flag) {
                        res++;
                    }
                }
            }
        }

        return res;
    }
}
